﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using RiskMan.DataClass;

namespace RiskMan.Views.Streling
{
    /// <summary>
    /// Interaction logic for Privod.xaml
    /// </summary>
    public partial class Privod
    {
        private SterlingLib.STIOrder _order;
        public Privod()
        {
            InitializeComponent();

            _order = RiskMan.MainWindow.StaticLevel.DataProvider.stiOrder;
            CmbxECN.ItemsSource =
                RiskMan.MainWindow.StaticLevel.DataProvider.DictionaryEcn.Select(a => a.Value).ToList();
            CmbxSide.ItemsSource = new List<string> { "B", "S" };
            CmbxTif.ItemsSource = MainWindow.StaticLevel.DataProvider.DictionaryTif.Select(a => a.Value).ToList();
            CmbxTypePrice.ItemsSource = MainWindow.StaticLevel.DataProvider.PriceType;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var date = DateTime.Now;
            _order.Symbol = TxbxSymbol.Text;
            _order.Account = TxbxAccount.Text;
            _order.Side = CmbxSide.SelectedValue.ToString();
            _order.Quantity = Convert.ToInt32(TxbxQuantity.Text);
            foreach (var item in MainWindow.StaticLevel.DataProvider.DictionaryEcn)
            {
                if (item.Value == CmbxECN.SelectedItem.ToString())
                    _order.Destination = item.Key.ToString();
            }
            foreach (var item in MainWindow.StaticLevel.DataProvider.DictionaryTif)
            {
                if (item.Value == CmbxTif.SelectedItem.ToString())
                    _order.Tif = item.Key.ToString();
            }            

            _order.LmtPrice = Convert.ToDouble(TxbxLinmitPrice.Text);
            _order.StpPrice = Convert.ToDouble(TxbxStopPrice.Text);
            _order.PriceType = SterlingLib.STIPriceTypes.ptSTILmt;


            _order.ClOrderID = TxbxAccount.Text + date.Year + date.Month + date.Day+date.Hour+date.Minute+date.Second+date.Millisecond;
            int ord = _order.SubmitOrder();
            if (ord != 0)
            {
                MessageBox.Show("Order Error: " + ord.ToString());
            }
        }
    }
}
